package cn.stylefeng.guns.modular.yingbao.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.yingbao.entity.Affiche;
import cn.stylefeng.guns.modular.yingbao.model.params.AfficheParam;
import cn.stylefeng.guns.modular.yingbao.service.AfficheService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 公告模块控制器
 *
 * @author zs
 * @Date 2020-01-14 09:27:22
 */
@CrossOrigin
@Controller
@RequestMapping("/affiche")
public class AfficheController extends BaseController {

    private String PREFIX = "/affiche";

    @Autowired
    private AfficheService afficheService;

    /**
     * 跳转到主页面
     *
     * @author zs
     * @Date 2020-01-14
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/affiche.html";
    }

    /**
     * 新增页面
     *
     * @author zs
     * @Date 2020-01-14
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/affiche_add.html";
    }

    /**
     * 编辑页面
     *
     * @author zs
     * @Date 2020-01-14
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/affiche_edit.html";
    }

    /**
     * 新增接口
     *
     * @author zs
     * @Date 2020-01-14
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(AfficheParam afficheParam) {
        this.afficheService.add(afficheParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author zs
     * @Date 2020-01-14
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(AfficheParam afficheParam) {
        this.afficheService.update(afficheParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author zs
     * @Date 2020-01-14
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(AfficheParam afficheParam) {
        this.afficheService.delete(afficheParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author zs
     * @Date 2020-01-14
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(AfficheParam afficheParam) {
        Affiche detail = this.afficheService.getById(afficheParam.getId());
        System.out.println(detail.toString());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author zs
     * @Date 2020-01-14
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(AfficheParam afficheParam) {
        return this.afficheService.findPageBySpec(afficheParam);
    }

    /**
     * 查看公告
     * @return
     */
    @PostMapping("queryAll")
    @ResponseBody
    public ResponseData queryAll(){
        return this.afficheService.queryAll();
    }

}


